<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserInfosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_infos', function (Blueprint $table) {
            $table->integer('user_id')->unsigned()->primary();
            //openid
            $table->string('open_id')->unique();
            //当前绑定设备号码
            $table->integer('current_device_id')->unsigned()->nullable()->index();
            //微信昵称
            $table->string('wx_nickname');
            //微信头像
            $table->string('wx_head_img_url');
            //是否关注
            $table->boolean('is_subscribe')->default(0);
            //性别
            $table->char('wx_sex');
            //市
            $table->string('wx_city');
            //省
            $table->string('wx_province');
            //国家
            $table->string('wx_country');
            //语言
            $table->string('wx_language')->nullable();
            //关注时间
            $table->integer('subscribe_time')->nullable();
            //用户姓名
            $table->string('name')->nullable();
            //安装地址
            $table->string('installation_address')->nullable();
            //手机
            $table->string('phone')->nullable();
            $table->char('sex')->default('0');
            $table->timestamps();

            $table->foreign('current_device_id')
                  ->references('id')
                  ->on('devices')
                  ->onDelete('cascade')
                  ->onUpdate('cascade');

            $table->foreign('user_id')
                  ->references('id')
                  ->on('users')
                  ->onDelete('cascade')
                  ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('user_infos');
    }
}
